<?php

namespace App\Repositories;

use App\Models\ChannelManager;
use InfyOm\Generator\Common\BaseRepository as iBaseRepository;

class ChannelManagerRepository extends iBaseRepository
{
    /**
     * @var array
     */
    protected $fieldSearchable = [
        'channel_id',
        'wechat_user_id',
        'status'
    ];

    /**
     * Configure the Model
     **/
    public function model()
    {
        return ChannelManager::class;
    }

    /**
     * 检查是否存在管理员
     */
    public function managerExists($channelId, $wechatUserId)
    {
        return $this->model->where(function ($query) use ($channelId, $wechatUserId) {
            $query->where('channel_id', $channelId)->orWhere('wechat_user_id', $wechatUserId);
        })
        ->first();
    }
}
